#include <buola/scene/techniques/clinetechnique.h>
#include <buola/scene/crendercontext.h>

#include "shaders/sPointFragment.h"
#include "shaders/sPointVertex.h"

namespace buola { namespace scene {

CLineTechnique::CLineTechnique()
{
    mProgram.CreateAndAttach(shaders::sPointVertex,shaders::sPointFragment);
    mProgram.BindFragmentData(0,"oFragColor");
    mProgram.BindAttribLocation(0,"iVertex");
    mProgram.BindAttribLocation(1,"iColor");
    mProgram.Link();

    uTransformation=mProgram.GetUniform("uMVPMatrix");
}

CLineTechnique::~CLineTechnique()
{
}

void CLineTechnique::Prepare(CRenderContext &pContext)
{
    if(pContext.mTechnique!=this)
    {
        mProgram.Use();
        glDisable(GL_LINE_SMOOTH);
        pContext.mTechnique=this;
    }

    uTransformation.SetValue(pContext.mProjectionMatrix*pContext.mViewMatrix*pContext.mModelMatrix);
}

CLineTechnique *CLineTechnique::Get()
{
    static CLineTechnique *lTechnique=new CLineTechnique;
    return lTechnique;
}

/*namespace scene*/ } /*namespace buola*/ }
